<template>
  <div v-loading="roomLoading" :fullscreen="true">
    <div>
      <el-select
        v-model="virtualRoom"
        placeholder="机房"
        style="width: 120px;"
        @change="virtualRoomChange"
      >
        <el-option
          v-for="item in virtualRoomOptions"
          :key="item.value"
          :value="item.value"
          :label="item.label"
        ></el-option>
      </el-select>
      <el-select
        style="width: 200px;"
        size="small"
        class="roomhosp_select"
        filterable
        v-model="hospCode"
        @change="hospChange"
        placeholder="请选择">
        <el-option
          v-for="(item,index) in mx_hospitalList"
          :key="index"
          :label="item.name"
          :value="item.code"
        ></el-option>
      </el-select>
      <el-cascader
        v-if="cascaderFlag && propsTree.length"
        ref="roomCascader"
        style="width: 230px;"
        :options="propsTree"
        v-model="deptRoom"
        placeholder="影像区域/部门/设备类型"
        @change="modalityChange"
      >
        <template slot-scope="{ node, data }">
          <span>{{data.label}}</span>
          <span v-if="!node.isLeaf"> ({{data.children.length}}) </span>
        </template>
      </el-cascader>
      <el-select
        v-if="roomIsUseSelectOption"
        size="small"
        class="roomhosp_select"
        style="width: 160px;"
        filterable
        v-model="roomTagCurrent"
        @change="roomChange"
        placeholder="请选择">
        <el-option
          v-for="(item,index) in roomOptions"
          :key="index"
          :label="item.label"
          :value="item.text"
        ></el-option>
      </el-select>
    </div>
    <div class="room_wrap" v-if="roomFlag && !roomIsUseSelectOption">
      <div class="room_box">
        <template v-if="roomOptions && roomOptions.length>0">
          <div
            class="room_list"
            :style="{flexWrap: roomTagAll?'wrap':'nowrap'}"
          >
            <div
              class="room_item"
              v-for="(item, index) in roomOptions"
              :key="index"
              @click="roomChange(item.text)"
              :class="{on: item.text === roomTagCurr}"
              :title="`检查设备：${item.value.split('$#')[1]}`"
            >{{item.label}}</div>
          </div>
        </template>
        <div v-else class="room_none">暂无机房</div>
        <div class="room_arr" @click="roomTagAllChange">
          <span class="layer_bg" v-show="!roomTagAll"></span>
          <span v-permission="['YJYY10001001002', 'YJYY10008002001']">
            {{roomTagAll?'收起':'展开'}}<i class="icon" :class="roomTagAll?'el-icon-arrow-up':'el-icon-arrow-down'"></i>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { setLocalStorage, getLocalStorage } from '@/utils/localStorage'
import {
  getDefaultCheckRoomArr,
  getCheckroomGroupListTree
} from '@/api/room'
import { setLocalStorageKey, getDefaultCheckRoom, setDefaultRoom, getDefaultRoom } from '@/utils/auth' // , setDefaultCheckRoom
import { virtualRoomInit } from '@/utils/constant'
import { isNull, getDeptRoomByKey, getRoomOptions, getRoomTagCurr, setRoomKeyToDeptRoom, setRoomTagCurr, setRoomOptions } from '@/utils/utils' // this.$utils , getLocalSetMemory
import { mapGetters } from 'vuex'
export default {
  name: 'RoomCascader',
  props: {
    room: {
      type: Array,
      default: []
    },
    refreshLocal: {
      type: Boolean,
      default: false
    },
    roomFlag: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      hospitalCode: this.$store.state.user.hospitalCode,
      roomLoading: false,
      isNewRoom: false,
      cascaderFlag: true,
      cNode: null,
      hospCode: this.$store.state.user.hospitalCode || '',
      deptRoom: [],
      propsTree: [],
      selectedRoom: [],
      roomTagAllShow: false,
      roomTagAll: false,
      roomTagCurr: '',
      roomTagCurrent: '',
      roomOptions: [],
      roomOptionsAll: [],
      roomTree: [],
      // 机房类型 0检查机房、1虚拟机房、2预约池,-1全部
      virtualRoom: '0',
      virtualRoomOptions: virtualRoomInit
    }
  },
  computed: {
    ...mapGetters(['roomIsUseSelectOption']),
    calRoom: {
      get() {
        return this.room
      },
      set(val) {
        this.$emit('update:room', val)
      }
    },
    appConfig() {
      return this.$store.state.settings.appConfig
    },
    unShowVirtualRoom() {
      return this.appConfig && this.appConfig.baseConfig && this.appConfig.baseConfig.unShowVirtualRoom || []
    }
  },
  async created() {
    // if (window.g.applyInfoHospital == 'wenfuer' || this.hospitalCode == '47000593033030211A1001') {
    //   this.virtualRoomOptions = this.virtualRoomOptions.filter(item => item.label != '虚拟机房')
    // }
    // console.log('unShowVirtualRoom', this.unShowVirtualRoom)
    this.virtualRoomOptions = this.virtualRoomOptions.filter(item => this.unShowVirtualRoom.indexOf(item.value) == -1)
    const vr = getLocalStorage('VirtualRoomKey')
    if (vr) {
      this.virtualRoom = vr + ''
    } else {
      setLocalStorage('VirtualRoomKey', this.virtualRoom)
    }
    this.$getHospitalList()
    // console.log('getDefaultRoom-in')
    await this.getDefaultRoom()
    // this.refresh()
  },
  mounted() {},
  methods: {
    async refresh(room) {
      this.init()
      if (room && room.length === 5) {
        // this.hospCode = room[0]
        if (this.propsTree.length === 0) {
          const roomTree = await getCheckroomGroupListTree(this.hospCode)
          this.roomTree = roomTree
          // console.log('refresh=>this.roomTree', this.roomTree)
          this.setTreeDefault()
        }
        const _r = [...room]
        // console.log('refresh=>_r', _r)
        // _r: 四个选项的全部数据 47000593033030211A1001 龙湾院区 SALT-DEP-CT SALT-MTYPE-CT 龙湾-ct-bak$#CT
        this.setCascaderDefault(_r)
      }
    },
    init(hospcode) {
      // console.log('init==>')
      this.hospCode = ''
      if (hospcode) {
        this.hospCode = hospcode
      }
      setLocalStorage('roomCascaderHospCode', this.hospCode)
      // this.cascaderFlag = false
      this.propsTree = []
      this.selectedRoom = []
      this.deptRoom = []
      this.calRoom = []
      this.$nextTick(() => {
        this.cascaderFlag = true
      })
    },

    async virtualRoomChange() {
      setLocalStorage('VirtualRoomKey', this.virtualRoom)
      // this.cascaderFlag = false
      this.propsTree = []
      this.selectedRoom = []
      this.deptRoom = []
      this.calRoom = []
      this.$nextTick(() => {
        this.cascaderFlag = true
      })
      this.isNewRoom = true
      this.roomLoading = true
      await this.getDefaultRoom()
      this.roomLoading = false
    },
    async hospChange(val) {
      // console.log('hospChange')
      setLocalStorage('yjyy-roomKeyToDeptRoom', JSON.stringify({}))
      setLocalStorageKey('roomTree', '')
      setDefaultRoom()
      setLocalStorage('VirtualRoomKey', -1)
      setRoomKeyToDeptRoom([])
      this.init(val)
      this.isNewRoom = true
      this.roomLoading = true
      await this.getDefaultRoom()
      this.roomLoading = false
      // this.$emit('changeHospitalCode', this.hospCode)
      setLocalStorage('roomCascaderHospCode', this.hospCode)
      await this.$store.dispatch('user/getHospitalAppSettings', this.hospCode)
    },
    modalityChange(data) {
      this.roomTagAll = false
      if (data.length > 0) {
        // 设置机房列表
        this.setRoomOptions()
        this.roomTagCurr = this.roomOptions && this.roomOptions.length > 0 ? this.roomOptions[0].text : ''
        // console.log('modalityChange=>roomTagCurr', this.roomTagCurr)
        this.roomChange(this.roomTagCurr)
      } else {
        this.$refs.roomCascader && this.$refs.roomCascader.$refs.panel && this.$refs.roomCascader.$refs.panel.clearCheckedNodes()
        this.deptRoom = []
        this.calRoom = []
        this.roomOptions = []
        this.roomTagCurr = ''
      }
    },
    roomChange(room) {
      // console.log('roomChange-room', room)
      setRoomTagCurr(room)
      // console.log('this.deptRoom=>roomChange', this.deptRoom)
      // console.log('setRoomKeyToDeptRoom33333333', this.deptRoom)
      setRoomKeyToDeptRoom(this.deptRoom)
      this.roomTagCurrent = room.split('$#')[0]
      this.selectedRoom = []
      let data = [...this.deptRoom]
      data.push(room)
      // 在这里动态更新this.parametersTypeByPart
      if (data.length > 0) {
        this.roomTagCurr = room
        this.selectedRoom.push(this.hospCode)
        this.selectedRoom = this.selectedRoom.concat(data)
        // console.log('================')
        // console.log('this.selectedRoom', this.selectedRoom)
        const _roomAndHospCode = JSON.parse(JSON.stringify(this.selectedRoom))
        // console.log('_roomAndHospCode', _roomAndHospCode)
        this.calRoom = [..._roomAndHospCode]
        // console.log('calRoom', this.calRoom)
        // console.log('================')
        if (this.refreshLocal) {
          // console.warn('roomChange=>user/resetDefaultCheckRoom', _roomAndHospCode)
          this.$store.dispatch('user/resetDefaultCheckRoom', _roomAndHospCode)
        }
        this.$emit('roomChange', _roomAndHospCode)
      } else {
        this.$refs.roomCascader && this.$refs.roomCascader.$refs.panel && this.$refs.roomCascader.$refs.panel.clearCheckedNodes()
        this.deptRoom = []
        this.calRoom = []
        this.roomOptions = []
        this.roomTagCurr = ''
      }
      // console.log('roomChange=>this.roomTagCurr', this.roomTagCurr)
    },
    // 设置默认数据
    getDefaultRoom() {
      // console.log('getDefaultRoom-into')
      return new Promise(async resolve => {
        // console.log('this.hospCode111', this.hospCode)
        setLocalStorage('roomCascaderHospCode', this.hospCode)
        const roomTree2 = await getCheckroomGroupListTree(this.hospCode)
        // console.log('roomTree2', roomTree2)
        this.roomTree = roomTree2
        this.isNewRoom = true
        // console.log('this.hospCode222', this.hospCode)
        let getDefaultCheckRoomData = await getDefaultCheckRoomArr(this.hospCode, this.isNewRoom)
        // console.warn('getDefaultRoom=>getDefaultCheckRoomData', getDefaultCheckRoomData)
        // room == YJYY-DEFAULTROOM  是一个数组
        let { room, roomTree } = getDefaultCheckRoomData
        // console.warn('getDefaultCheckRoomData=>room', room)
        // console.log('this.roomTree', this.roomTree)
        // console.log('roomTree', roomTree)
        if (getDeptRoomByKey().length) {
          this.deptRoom = getDeptRoomByKey()
        } else {
          this.deptRoom = []
        }
        // console.warn('this.deptRoom', this.deptRoom)
        let roomTagCurr = getDefaultCheckRoom()
        // console.log('roomTagCurr', roomTagCurr)
        const len = roomTagCurr.length
        if (len > 0) {
          this.roomTagCurr = roomTagCurr[len - 1]
          setRoomTagCurr(this.roomTagCurr)
          // console.log('getDefaultRoom=>this.roomTagCurr', this.roomTagCurr)
        } else {
          // this.$message.warning('该医院未设置检查机房')
        }
        // 权限配置的缓存若存在，优先取权限配置中的值
        // let localMomery = getLocalSetMemory()
        // // console.log('localMomery', localMomery)
        // if (localMomery.depArea && localMomery.dep && localMomery.modalitytype) {
        //   // setDefaultCheckRoom()
        //   // console.log('= = =')
        //   let deptRoom = []
        //   let isHavaRequalAreaName = false
        //   let isHavaRequalDep = false
        //   let isHavaRequalModalitytype = false
        //   // console.log('getDefaultRoom=>localMomery', localMomery)
        //   roomTree.forEach(item => {
        //     if (item.label == localMomery.depArea) {
        //       isHavaRequalAreaName = true
        //       deptRoom.push(item.value)
        //       item.children.forEach(itemDep => {
        //         if (itemDep.label == localMomery.dep) {
        //           isHavaRequalDep = true
        //           deptRoom.push(itemDep.value)
        //           itemDep.children.forEach(itemMtype => {
        //             if (itemMtype.label == localMomery.modalitytype) {
        //               isHavaRequalModalitytype = true
        //               deptRoom.push(itemMtype.value)
        //             }
        //           })
        //         }
        //       })
        //     }
        //   })
        //   if (isHavaRequalAreaName && isHavaRequalDep && isHavaRequalModalitytype) {
        //     this.deptRoom = deptRoom
        //   } else {
        //     this.deptRoom = getDeptRoomByKey()
        //   }
        //   // console.log('setRoomKeyToDeptRoom444444', this.deptRoom)
        //   setRoomKeyToDeptRoom(this.deptRoom)
        //   // console.warn('getDefaultRoom=>this.deptRoom1', this.deptRoom)
        //   // if (!isHavaRequalAreaName || !isHavaRequalDep || !isHavaRequalModalitytype) { // 权限配置的缓存若不存在，就去取缓存映射中的值
        //   //   if (getDeptRoomByKey().length) {
        //   //     this.deptRoom = getDeptRoomByKey()
        //   //   } else {
        //   //     this.deptRoom = []
        //   //   }
        //   // }
        //   // console.log('this.deptRoom', this.deptRoom)
        // } else { // 权限配置的缓存若不存在，就去取缓存映射中的值
        //   // console.log('= = =, = != != else')
        //   // console.log('getDeptRoomByKey()', getDeptRoomByKey())
        //   if (getDeptRoomByKey().length) {
        //     this.deptRoom = getDeptRoomByKey()
        //   } else {
        //     this.deptRoom = []
        //   }
        //   // console.warn('this.deptRoom', this.deptRoom)
        //   let roomTagCurr = getDefaultCheckRoom()
        //   // console.log('roomTagCurr', roomTagCurr)
        //   const len = roomTagCurr.length
        //   if (len > 0) {
        //     this.roomTagCurr = roomTagCurr[len - 1]
        //     setRoomTagCurr(this.roomTagCurr)
        //     // console.log('getDefaultRoom=>this.roomTagCurr', this.roomTagCurr)
        //   } else {
        //     // this.$message.warning('该医院未设置检查机房')
        //   }
        // }
        // 注释
        // else if (localMomery.depArea && !localMomery.dep && !localMomery.modalitytype) {
        //   // console.log('= != !=')
        //   // console.warn('jinrudaozheli')
        //   let deptRoom = []
        //   let isHavaRequalAreaName = false
        //   let isHavaRequalDep = false
        //   let isHavaRequalModalitytype = false
        //   // console.log('localMomery', localMomery)
        //   this.roomTree.forEach(item => {
        //     if (item.label == localMomery.depArea) {
        //       isHavaRequalAreaName = true
        //       deptRoom.push(item.value)
        //       if (item.children.length) {
        //         deptRoom.push(item.children[0].value)
        //         isHavaRequalDep = true
        //         if (item.children[0].children.length) {
        //           deptRoom.push(item.children[0].children[0].value)
        //           isHavaRequalModalitytype = true
        //         }
        //       }
        //     }
        //   })
        //   this.deptRoom = deptRoom
        //   setRoomKeyToDeptRoom(this.deptRoom)
        //   // 当影响区域/部门/设备与权限配置中的参数对不上的时候，就存取缓存
        //   if (!isHavaRequalAreaName || !isHavaRequalDep || !isHavaRequalModalitytype) { // 权限配置的缓存若不存在，就去取缓存映射中的值
        //     if (getDeptRoomByKey().length) {
        //       this.deptRoom = getDeptRoomByKey()
        //     } else {
        //       this.deptRoom = []
        //     }
        //   }
        //   // console.log('this.deptRoom', this.deptRoom)
        // }
        // ============================================

        // console.log('this.deptRoom.length === 0', this.deptRoom.length === 0)
        if (this.deptRoom.length === 0) {
          // // console.log('机房选择组件，设置模板机房')
          // let { room, roomTree } = await getDefaultCheckRoomArr(this.hospCode, this.isNewRoom)
          // console.log('room, roomTree', room, roomTree)
          const _room = room ? JSON.parse(JSON.stringify([...room])) : []
          // console.warn('this.deptRoom.length === 0_room', _room)
          // _room: 四个选项的全部数据 47000593033030211A1001 龙湾院区 SALT-DEP-CT SALT-MTYPE-CT 龙湾-ct-bak$#CT
          this.roomTree = roomTree
          this.setCascaderDefault(_room)
          // console.log('setTreeDefault_before->this.deptRoom', this.deptRoom)
          this.setTreeDefault()
          if (this.refreshLocal) {
            setLocalStorageKey('roomTree', JSON.stringify(roomTree))
          }
          this.isNewRoom = false
          // console.log('this.deptRoom.length === 0=>deptRoom', this.deptRoom)
        } else {
          // console.log('this.hospCode', this.hospCode)
          // let { room, roomTree } = await getDefaultCheckRoomArr(this.hospCode, this.isNewRoom)
          // console.warn('room, roomTree', room, roomTree)
          // console.log('this.deptRoom', this.deptRoom)
          // let _room = [this.hospCode, ...this.deptRoom]
          let _room = room
          // console.log('_room', _room)
          let defualtRoom = ''
          // 获取_room对应的默认机房
          // console.log('roomTree=>', roomTree)
          roomTree.forEach(item => {
            if (item.label == this.deptRoom[0]) {
              // defualtRoom =
              item.children.forEach(itemDep => {
                if (itemDep.value == this.deptRoom[1]) {
                  itemDep.children.forEach(itemMtype => {
                    if (itemMtype.value == this.deptRoom[2]) {
                      let isHavaRoom = false
                      itemMtype.children.forEach(roomItem => {
                        if (roomItem.value == getDefaultRoom()[4]) {
                          isHavaRoom = true
                          defualtRoom = roomItem.value
                        }
                      })
                      if (!isHavaRoom) {
                        defualtRoom = itemMtype.children[0].value
                      }
                    }
                  })
                }
              })
            }
          })
          // let roomTree = getLocalStorage('roomTree')
          // // console.log('roomTree', roomTree)
          // const _room = room ? JSON.parse(JSON.stringify([...room])) : []
          // // _room: 四个选项的全部数据[47000593033030211A1001,龙湾院区，SALT-DEP-CT,SALT-MTYPE-CT,龙湾-ct-bak$#CT]
          this.roomTree = roomTree
          // console.log('setTreeDefault_before->this.deptRoom', this.deptRoom)
          this.setTreeDefault()
          if (this.refreshLocal) {
            setLocalStorageKey('roomTree', JSON.stringify(roomTree))
          }
          this.isNewRoom = false
          // let roomOptions = getRoomOptions()
          // let roomTagC = getRoomTagCurr()
          // // console.warn('roomTagC???', roomTagC)
          // let isFind = false
          // // console.log('roomOptions', roomOptions)
          // // console.log('roomOptions && roomOptions.length', roomOptions && roomOptions.length)
          // if (roomOptions && roomOptions.length) {
          //   roomOptions.forEach(item => {
          //     if (item.text == roomTagC) {
          //       isFind = true
          //     }
          //   })
          // }
          // 这里有问题=======修复中
          // if (isFind) {
          //   defualtRoom = roomTagC
          // }
          // console.warn('=>defualtRoom???', defualtRoom)
          // console.warn('_room???', _room)
          if (defualtRoom) {
            if (_room.length == 5) {
              _room.pop()
            }
            _room.push(defualtRoom)
          }
          // // console.warn('setCascaderDefault=>_room', _room)
          this.setCascaderDefault(_room)
          // console.log('this.deptRoom.length !== 0=>deptRoom', this.deptRoom)
        }
        // console.log('getDefaultRoom=>this.deptRoom', this.deptRoom)
        // console.log('hospChange=>propsTree', this.propsTree)
        resolve()
      })
    },
    setTreeDefault() {
      // console.log('setTreeDefault=>this.roomTree', this.roomTree)
      let roomtree = []
      if (this.roomTree && this.roomTree.length) {
        roomtree = JSON.parse(JSON.stringify(this.roomTree))
      }
      let props = []
      let roomObj = {}
      const setTree = (a, b, k, kv) => {
        k = k ? k + '#' + kv : kv
        a.forEach(item => {
          if (item.children && item.children.length > 0) {
            const imc = item.children[0]
            let o = {
              text: item.text,
              label: item.label,
              value: item.value
            }
            if (imc.children && imc.children.length > 0) {
              o.children = []
              setTree(item.children, o.children, k, item.value)
            } else {
              roomObj[`'${k + '#' + item.value}'`] = item.children
            }
            b.push(o)
          } else {
            // // console.log('333333333', k)
          }
        })
      }
      let _k = ''
      setTree(roomtree, props, _k, '')
      // console.log('setTreeDefault=>props===', props)
      this.propsTree = props
      // console.log('propsTree', this.propsTree)
      if (this.propsTree.length <= 0) {
        this.$message.warning('该医院未设置检查机房')
      }
      this.roomOptionsAll = roomObj
      // console.log('setTreeDefault=>setRoomOptions_before->this.deptRoom', this.deptRoom)
      this.setRoomOptions()
    },
    // 设置机房联级选择
    setCascaderDefault(room) {
      // room: 四个选项的全部数据 47000593033030211A1001 龙湾院区 SALT-DEP-CT SALT-MTYPE-CT 龙湾-ct-bak$#CT
      // console.warn('setCascaderDefault->room', room)
      this.calRoom = [...room]
      if (this.refreshLocal) {
        // console.warn('setCascaderDefault=>user/resetDefaultCheckRoom', room)
        this.$store.dispatch('user/resetDefaultCheckRoom', room)
      }
      this.hospCode = room.length > 0 ? room[0] : this.hospCode
      // this.cascaderFlag = false
      // console.log('room=>setCascaderDefault22', room)
      let _r = [...room]
      // console.log('_r1', _r)
      if (_r.length > 0) {
        _r.shift()
        const mapkey = getDeptRoomByKey()
        // console.log('mapkey', mapkey)
        if (isNull(mapkey)) {
          // console.log('setRoomKeyToDeptRoom666666666', _r)
          setRoomKeyToDeptRoom(_r)
        }
        // console.log('before shift _r', _r)
        let roomTagC = getRoomTagCurr()
        let roomTagCurr = getDefaultCheckRoom()
        const len = roomTagCurr.length
        if (len > 0) {
          roomTagC = roomTagCurr[len - 1]
        } else {
          // this.$message.warning('该医院未设置检查机房')
        }
        let roomOptions = getRoomOptions()
        // let roomArr = roomOptions.map(item => item.text)
        // console.log('roomOptions', roomOptions)
        let isFind = false
        if (roomOptions && roomOptions.length) {
          roomOptions.forEach(item => {
            if (item.text == roomTagC) {
              isFind = true
            }
          })
        }
        // console.log('isFind', isFind)
        if (isFind) {
          this.roomTagCurr = roomTagC
          this.roomTagCurrent = roomTagC.split('$#')[0]
        } else {
          // console.log('_r_r_r_r_r_r', _r)
          // let r = _r.pop()
          // console.log('rrrrrrrrrrr', r)
          // this.roomTagCurr = _r.pop()
          // this.roomTagCurrent = r.split('$#')[0]
          // this.roomTagCurr = r
          // console.warn('this.roomTagCurr', this.roomTagCurr)
        }
        // console.warn('this.roomTagCurr=>setCascaderDefault', this.roomTagCurr)
        setRoomTagCurr(this.roomTagCurr)
      }
      // console.log('_r2', _r)
      // 得先存储一波deptRoom
      // 权限配置的缓存若存在，优先取权限配置中的值
      // let localMomery = getLocalSetMemory()
      // // console.log('localMomery', localMomery)
      // if (localMomery.depArea && localMomery.dep && localMomery.modalitytype) {
      //   let deptRoom = []
      //   // console.log('this.roomTree=>看这里', this.roomTree)
      //   let isHavaRequalAreaName = false
      //   let isHavaRequalDep = false
      //   let isHavaRequalModalitytype = false
      //   this.roomTree.forEach(item => {
      //     if (item.label == localMomery.depArea) {
      //       isHavaRequalAreaName = true
      //       deptRoom.push(item.value)
      //       item.children.forEach(itemDep => {
      //         // console.log('itemDep.label', itemDep.label)
      //         // console.log('localMomery.dep', localMomery.dep)
      //         if (itemDep.label == localMomery.dep) {
      //           isHavaRequalDep = true
      //           deptRoom.push(itemDep.value)
      //           itemDep.children.forEach(itemMtype => {
      //             // console.log('itemMtype.label', itemMtype.label)
      //             // console.log('localMomery.modalitytype', localMomery.modalitytype)
      //             if (itemMtype.label == localMomery.modalitytype) {
      //               isHavaRequalModalitytype = true
      //               deptRoom.push(itemMtype.value)
      //             }
      //           })
      //         }
      //       })
      //     }
      //   })
      //   if (isHavaRequalAreaName && isHavaRequalDep && isHavaRequalModalitytype) {
      //     this.deptRoom = deptRoom
      //   } else {
      //     // 当影响区域/部门/设备与权限配置中的参数对不上的时候，就存取缓存 获取没设置全的时候
      //     let deptRoom = getDeptRoomByKey()
      //     // console.log('getDeptRoomByKey()', getDeptRoomByKey())
      //     if (deptRoom.length) {
      //       // console.log('有缓存', deptRoom)
      //       this.deptRoom = deptRoom
      //     } else {
      //       this.deptRoom = _r
      //     }
      //   }
      //   // console.log('this.deptRoom', this.deptRoom)
      // } else { // 权限配置的缓存若不存在，就去取缓存映射中的值
      //   if (getDeptRoomByKey().length) {
      //     // console.log('有缓存')
      //     this.deptRoom = getDeptRoomByKey()
      //   } else {
      //     this.deptRoom = _r
      //   }
      // }
      if (getDeptRoomByKey().length) {
        // console.log('有缓存')
        this.deptRoom = getDeptRoomByKey()
      } else {
        this.deptRoom = _r
      }
      // 注释
      // else if (localMomery.depArea && !localMomery.dep && !localMomery.modalitytype) {
      //   // console.log('jinrudaozheli')
      //   let deptRoom = []
      //   let isHavaRequalAreaName = false
      //   let isHavaRequalDep = false
      //   let isHavaRequalModalitytype = false
      //   // console.log('this.roomTree', this.roomTree)
      //   this.roomTree.forEach(item => {
      //     if (item.label == localMomery.depArea) {
      //       isHavaRequalAreaName = true
      //       deptRoom.push(item.value)
      //       if (item.children.length) {
      //         deptRoom.push(item.children[0].value)
      //         isHavaRequalDep = true
      //         if (item.children[0].children.length) {
      //           deptRoom.push(item.children[0].children[0].value)
      //           isHavaRequalModalitytype = true
      //         }
      //       }
      //     }
      //   })
      //   this.deptRoom = deptRoom
      //   // console.log('jinrudaozheli=>this.deptRoom111', this.deptRoom)
      //   // 当影响区域/部门/设备与权限配置中的参数对不上的时候，就存取缓存
      //   if (!isHavaRequalAreaName || !isHavaRequalDep || !isHavaRequalModalitytype) {
      //     // console.log('进入这里')
      //     let deptRoom = getDeptRoomByKey()
      //     if (deptRoom.length) {
      //       this.deptRoom = deptRoom
      //     } else {
      //       this.deptRoom = _r
      //     }
      //   }
      //   // console.log('jinrudaozheli=>this.deptRoom222', this.deptRoom)
      // }
      // console.log('setCascaderDefault=>setRoomOptions_before->this.deptRoom', this.deptRoom)
      this.setRoomOptions()
      // setLocalStorage('deptRoom', this.deptRoom.join(','))
      // console.log('this.deptRoom=>setCascaderDefault', this.deptRoom)
      // this.roomTagCurr = getRoomTagCurr()
      // this.roomTagCurrent = getRoomTagCurr().split('$')[0]
      let roomTagCurr = getDefaultCheckRoom()
      // console.log('roomTagCurr', roomTagCurr)
      const len = roomTagCurr.length
      if (len > 0) {
        this.roomTagCurr = roomTagCurr[len - 1]
        this.roomTagCurrent = roomTagCurr[len - 1].split('$#')[0]
      } else {
        // this.$message.warning('该医院未设置检查机房')
      }
      // console.log('this.roomTagCurr=>setCascaderDefault', this.roomTagCurr)
      this.$nextTick(() => {
        this.cascaderFlag = true
      })
      this.$nextTick(() => {
        this.$emit('roomChange', room)
      }, 200)
    },
    setRoomOptions() {
      // console.log('setRoomOptions')
      // console.warn('this.deptRoom1', this.deptRoom)
      let dr = this.deptRoom // .splice(0, 3)
      // this.deptRoom = dr
      let deptR = dr.join('#')
      // console.warn('deptR', deptR)
      // console.warn('setRoomOptions->roomOptionsAll', this.roomOptionsAll)
      // // console.log('roomOptionsAll', JSON.stringify(this.roomOptionsAll))
      let nOpt = this.roomOptionsAll[`'${deptR}'`]
      if (isNull(nOpt)) {
        // console.warn('nOpt is null => dr', dr)
        deptR = `${dr[0]}#${dr[1]}#${dr[2]}`
        nOpt = this.roomOptionsAll[`'${deptR}'`]
        // console.warn('nOpt is null => nOpt', nOpt)
      }
      let newDR = []
      dr[0] && newDR.push(dr[0])
      dr[1] && newDR.push(dr[1])
      dr[2] && newDR.push(dr[2])
      // console.log('setRoomOptions=>newDR', newDR)
      const mapkey = getDeptRoomByKey()
      // console.warn('mapkey', mapkey)
      if (isNull(mapkey)) {
        // console.log('setRoomKeyToDeptRoom7777777777', newDR)
        setRoomKeyToDeptRoom(newDR)
      }
      let _options = nOpt ? JSON.parse(JSON.stringify(nOpt)) : []
      // let _options = JSON.parse(JSON.stringify(this.roomOptions))
      // console.log('setRoomOptions=>_options', _options)
      this.roomOptions = [..._options]
      // console.warn('this.roomOptions====>', this.roomOptions)
      setRoomOptions(this.roomOptions)
      // console.warn('this.deptRoom2', this.deptRoom)
      if (this.deptRoom.length >= 4) {
        // 设置一个默认选中的机房(重要)
        // this.roomTagCurr = this.deptRoom[3]
        this.roomTagCurr = this.roomOptions && this.roomOptions.length && this.roomOptions[0].value
        this.deptRoom = newDR
      }
      // console.log('setRoomOptions=>this.deptRoom', this.deptRoom)
      if (this.deptRoom && this.deptRoom.length == 3) {
        // const roomOptions = getRoomOptions()
        if (!isNull(this.roomOptions)) {
          // // console.log('---===getRoomOptions()', getRoomOptions())
          let currentRoom = getDefaultRoom()[4] // this.roomOptions[0].value
          // this.deptRoom.push(currentRoom)
          // 如果roomOptions不为空，则遍历一下是否有缓存yjyy-defaultroom中的room YJYY-DEFAULTROOM yjyy-roomOptions
          let isHavaRoom = false
          this.roomOptions.forEach(roomItem => {
            if (roomItem.value == currentRoom) {
              isHavaRoom = true
            }
          })
          if (!isHavaRoom) {
            currentRoom = this.roomOptions[0].value
          }
          setRoomTagCurr(currentRoom)
          this.roomTagCurr = currentRoom
        }
      }
      // console.log('setRoomOptions=>this.roomTagCurr', this.roomTagCurr)
      // 如果万一所选机房缓存为空，则取第一个机房
      // if (isNull(getRoomTagCurr())) {
      //   setRoomTagCurr(this.roomTagCurr)
      // } else {
      //   let result = this.roomOptions.filter(item => item.label == this.roomTagCurr)
      //   // console.log('result=>', result)
      //   if (result.length) {
      //     setRoomTagCurr(this.roomTagCurr)
      //   } else {
      //     // console.warn('------------------未设置当前机房-------------------')
      //     // // console.log('this.roomOptions=>', this.roomOptions)
      //     // this.roomTagCurr = getRoomTagCurr()
      //     // setRoomTagCurr(this.roomTagCurr)
      //     if (!isNull(getRoomOptions())) {
      //       let currentRoom = getRoomOptions()[0].value
      //       setRoomTagCurr(currentRoom)
      //     }
      //   }
      // }
      // // console.warn('setRoomOptions=>this.roomTagCurr', this.roomTagCurr)
      // this.$nextTick(() => {
      //   this.$emit('roomChange', this.roomTagCurr)
      // }, 500)
    },
    roomTagAllChange() {
      this.roomTagAll = !this.roomTagAll
    }
  }
}
</script>

<style lang="scss" scoped>
.roomhosp_select{
  vertical-align: top;
}
.room_box{
  // max-width: 538px;
  padding-right: 56px;
  position: relative;
}
.room_list{
  margin-top: 6px;
  display: flex;
  flex-wrap: nowrap;
  overflow: hidden;
  .room_item{
    border-radius: 2px;
    border: solid 1px #ddd;
    text-align: center;
    white-space: nowrap;
    font-size: 14px;
    color: #333;
    padding: 0 4px;
    margin: 0 2px;
    cursor: pointer;
    line-height: 1.6em;
    transition: all 0.2s linear;
    &:hover{
      color: #00C0EF;
      border: solid 1px #00C0EF;
    }
    &.on{
      color: #fff;
      background-color: #00C0EF;
      border: solid 1px #00C0EF;
    }
  }
}
.room_none{
  font-size: 14px;
  color: #666;
  line-height: 1.6em;
}
.room_arr{
  font-size: 12px;
  position: absolute;
  color: #00C0EF;
  right: 0px;
  top: 0px;
  padding: 2px 6px 2px 10px;
  background-color: #fff;
  .layer_bg{
    display: block;
    width: 30px;
    height: 20px;
    position: absolute;
    left: -25px;
    top: 0px;
    background: linear-gradient(left,rgba(255,255,255,0.2),rgba(255,255,255,1));
    background: -moz-linear-gradient(left,rgba(255,255,255,0.2),rgba(255,255,255,1));
    background: -webkit-gradient(linear,0 right,0 left,from(rgba(255,255,255,0.2)),to(rgba(255,255,255,1)));
    background: -o-linear-gradient(left,rgba(255,255,255,0.2),rgba(255,255,255,1));
  }
  cursor: pointer;
  .icon{
    vertical-align: -1px;
    font-size: 16px;
  }
}
</style>
